package com.java.base.exercise.jvm;

/**
 * @Author RenPu
 * @Date 2021/10/22 12:02
 * @Version 1.0
 * @Description: <clinit> 构造器方法，在多线程下，可以正确的加锁，同步，只有一个线程可以进行调用<clinit>,其他线程都需要阻塞
 **/
public class DeadLoopClass {

    static {
        if (true) {
            System.out.println(Thread.currentThread() + "init DeadLoopClass");
            while (true) {

            }
        }
    }

    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread() + "run start.....");
                DeadLoopClass deadLoopClass = new DeadLoopClass();
                System.out.println(Thread.currentThread() + "run end ........");
            }
        };


        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        thread1.start();
        thread2.start();


    }


}
